package pos.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import java.util.*;

import pos.domain.*;

public class JDBCEventoDAO implements IEventoDAO {
	public List selectAllEventos() {
        Connection conn = ConnectionManager.getInstance().checkOut();

        PreparedStatement stmt = null;
        List searchResults = new LinkedList();
        ResultSet result = null;

        try {

            String sql = "SELECT * FROM evento";
            stmt = conn.prepareStatement(sql); 
            stmt.executeQuery();
            result = stmt.executeQuery();

            while (result.next()) {
                evento temp = new evento();
                temp.setIdEvento("idEvento");
                temp.setDescripcion("descripcion");
                temp.setF(new Date("f"));
              
                
                searchResults.add(temp);
            }
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            ConnectionManager.getInstance().checkIn(conn);
            try {
                if (result != null)
                    result.close();
                if (stmt != null)
                    stmt.close();
            } catch (SQLException e) {
            }

        }
        return searchResults;
    }

    public evento select(Connection conn, String eventoOID) {
        PreparedStatement stmt = null;
        ResultSet result = null;
        evento p = null;
        String sql = "SELECT * FROM evento WHERE (OID = ?) ";

        try {
            stmt = conn.prepareStatement(sql);
            stmt.setString(1, eventoOID);
            result = stmt.executeQuery();

            result.next();
            p = new evento();
            p.setIdEvento("idEvento");
            p.setDescripcion("descripcion");
            p.setF(new Date("f"));
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (result != null) {
                    result.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
        return p;
    }

    public String selectEventoOID(Connection conn, String eventoid) {
        PreparedStatement stmt = null;
        ResultSet result = null;
        String oidp = null;
        String sql = "SELECT * FROM evento WHERE (productid = ?) ";

        try {
            stmt = conn.prepareStatement(sql);
            stmt.setString(1, eventoid);
            result = stmt.executeQuery();

            result.next();
            oidp = result.getString("OID");
            
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (result != null) {
                    result.close();
                }
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
        }
        return oidp;
    }
}
